/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
  CCell, Table, TableBody, TableRow, Text, BlobInputList, TableHead,
} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, RepLink, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {objNestSet} from "../../../common/tool";
import {
    useOmnipotentPrefTitle1R, useOmnipotentPrefUahit
} from "../../hook/useOmnipotentPref";

export interface Props extends InternalItemProps {
    iAname?: string[];
}
//带下标字符 推荐使用m<sup>&#179;</sup>或m³（如果你的文档编码是UTF-8）来表示立方米
export const item数综合 = [
    ['基灰分', [{t:'收到基灰分',},{t:<>A<sub>ar</sub></>,}], '试验数据', '%'],
    ['基水分', [{t:'收到基水分' },{t:<>M<sub>ar</sub></>,}], '试验数据', '%'],
    ['无灰挥发', [{t:'干燥无灰基挥发分' },{t:<>V<sub>def</sub></>,}], '试验数据', '%'],
    ['基低位发', [{t:'燃料收到基低位发热量' },{t:<>Q<sub>net,v,ar</sub></>,}], '试验数据', 'kJ/kg(m³)'],
    ['飞灰可燃', [{t:'飞灰可燃物含量' },{t:<>C<sub>as</sub></>,}], '试验数据', '%'],
    ['漏煤可燃', [{t:'漏煤可燃物含量' },{t:<>C<sub>cl</sub></>,}], '试验数据', '%'],
    ['炉渣可燃', [{t:'炉渣可燃物含量' },{t:<>C<sub>s</sub></>,}], '试验数据', '%'],
    ['飞占总灰', [{t:'飞灰占总灰量重量百分比' },{t:'／'}], '选取数据', '%'],
    ['漏占总灰', [{t:'漏煤占总灰量重量百分比' },{t:'／'}], '选取数据', '%'],
    ['炉渣占总', [{t:'炉渣占总灰量重量百分比' },{t:'／'}], '选取数据', '%'],
    ['CO2含', [{t:<>排烟处CO<sub>2</sub>含量</>},{t: <>CO<sub>2</sub>'</>}], '试验数据', '%'],
    ['烟O2含', [{t:<>排烟处O<sub>2</sub>含量</>},{t: <>O<sub>2</sub>'</>}], '试验数据', '%'],
    ['烟处CO', [{t:'排烟处CO含量' },{t:'CO\'',}], '试验数据', '%'],
    ['过量空系', [{t:'排烟处过量空气系数' },{t:<>α<sub>ds</sub></>}], '计算数据', ],
    ['冷空气温', [{t:'入炉冷空气温度' },{t:<>t<sub>ca</sub></>}], '试验数据', '°C'],
    ['排烟温', [{t:'锅炉排烟温度' },{t:<>t<sub>ds</sub></>}], '试验数据', '°C'],
    ['m值', [{t:'m值' },{t:'／'} ], '选取数据', ],
    ['n值', [{t:'n值' },{t:'／'} ], '选取数据', ],
    ['炉渣温', [{t:'炉渣温度' },{t:<>t<sub>ls</sub></>}], '选取数据', '°C'],
    ['炉渣焓', [{t:'炉渣焓' },{t:<>(ct)<sub>s</sub></>}], '选取数据', 'kJ/kg'],
    ['烟热损', [{t:'排烟热损失' },{t:<>q<sub>2</sub></>}], '计算数据', '%'],
    ['气未全燃', [{t:'气体未完全燃烧热损失' },{t:<>q<sub>3</sub></>}], '计算数据', '%'],
    ['固未全燃', [{t:'固体未完全燃烧热损失' },{t:<>q<sub>4</sub></>}], '计算数据', '%'],
    ['散热损', [{t:'散热损失' },{t:<>q<sub>5</sub></>}], '计算数据', '%'],
    ['物理热损', [{t:'灰渣物理热损失' },{t:<>q<sub>6</sub></>}], '计算数据', '%'],
    ['简效率', [{t:'简单测试效率' },{t:<>η<sub>2</sub></>}], '计算数据', '%']
];

export const itemA数综合: string[] = [ ];
item数综合.forEach(([name, title, initIsp], i: number) => {
    itemA数综合.push(name as string);
});

export const Comprehensive =
    React.forwardRef((
        {children, show, alone = true, refWidth, label, }: Props, ref
    ) => {
        const {inp, setInp} = useItemInputControl({ref});
        const [getInpFilter] = useMeasureInpFilter(null, itemA数综合,);
        const titNode=useOmnipotentPrefTitle1R({config:item数综合});
        return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={label!}>
                <Text variant="h5">{label}：</Text>
                {item数综合.map(([name, _1, _2, unit]: any, i: number) => {
                    return (<React.Fragment key={i}>
                        <div css={{display: 'flex', flexWrap: 'wrap', alignItems: 'center'}}>
                            {titNode[i]}
                            &nbsp;
                            <div css={{display: 'inline-flex', alignItems: 'center'}}>
                                &nbsp;测试数据
                                <BlobInputList value={inp?.[name]?.m ?? ''}
                                               style={{display: 'inline-flex', width: '15rem'}} rows={1}
                                               onListChange={v => objNestSet(name, 'm', v || undefined, inp, setInp)}/>
                                {unit}
                            </div>
                        </div>
                    </React.Fragment>);
                })}
                {children}
            </InspectRecordLayout>
        );
    });


const tailRender=(orc: any, name: string,lix:number,unit:any)=><>
    <CCell><div css={{whiteSpace: 'pre-wrap'}}>{orc?.[name]?.m??'／'}</div></CCell>
</>;
// const config挠测量=[...config挠度.slice(0,5),  ['','d',0], ...config挠度.slice(5)]  as Each_ZdSetting[];
export const ComprehensiveVw = ({orc, rep}: { orc: any, rep: any }
) => {
    const [renderBrkTest]=useOmnipotentPrefUahit({orc, config:item数综合,
          tailRender, pcols:1, noNo:false, unitCel:true});
    return <>
        <div css={{"@media print": {paddingBottom: '3.5rem', pageBreakInside: 'avoid'}} }>
            <Text id='Comprehensive' variant="h2" css={{textAlign: 'center', marginTop: '1rem',
            }}>四、测试数据综合表</Text>
            <div css={{display: 'flex', justifyContent: 'space-between'}}>
                <Text></Text>
                <Text>报告编号：{rep.isp.no}</Text>
            </div>
        </div>
        <Table fixed={ ["4.8%","33%","9%","10%","11%","%"] } css={{borderCollapse: 'collapse', "@media print": {marginTop: '-3.5rem'}}} tight  miniw={800}>
            <TableHead>
                <TableRow>
                    <CCell>序号</CCell><CCell>名 称</CCell><CCell>符号</CCell>
                    <CCell>单位</CCell><CCell>数据来源</CCell><CCell>测试数据</CCell>
                </TableRow>
            </TableHead>
            <TableBody>
                <RepLink rep={rep} tag={"Comprehensive"}>
                    {renderBrkTest}
                </RepLink>
            </TableBody>
        </Table>
    </>;
};
